package icu.sehnen.coach.controller;



import icu.sehnen.coach.entity.Coach;
import icu.sehnen.coach.service.ICoachService;
import icu.sehnen.common.result.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author icu.sehnen
 * @since 2021-04-26
 */
@Api(tags = "教练模块说明")
@RestController
@RequestMapping("/coach")
public class CoachController {
    @Autowired
    ICoachService coachService;
    @GetMapping("/list")
    @ApiOperation("查询所有教练接口")
    public CommonResult<List<Coach>> findAll(@ApiParam("传入名字的模糊查询") String query){
        List<Coach> coachModelList= coachService.list();
        return  CommonResult.success(coachModelList);
    }
    @PostMapping("/add")
    public  CommonResult add(Coach coach){
       Boolean res= coachService.save(coach);
        if(res){
            return  CommonResult.success();
        }
        return  CommonResult.failed();
    }
    @PostMapping("/update")
    public CommonResult update(Coach coach){
     Boolean  res= coachService.updateById(coach);
       if(res ){
           return  CommonResult.success();
       }
       return  CommonResult.failed();
    }
    @GetMapping("/find/{id}")
    public CommonResult find(@PathVariable Long id){
        Coach coach=coachService.getById(id);
        return  CommonResult.success(coach);
    }

    @PostMapping("/delete/{id}")
    public CommonResult deleteCoachById(@PathVariable Long id){
        boolean b = coachService.removeById(id);
        if(b){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

}
